from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.throttling import AnonRateThrottle
from rest_framework.viewsets import ViewSet, GenericViewSet, ModelViewSet
from rest_framework.mixins import ListModelMixin,DestroyModelMixin,CreateModelMixin,UpdateModelMixin,RetrieveModelMixin

from tushu.auth_my import LoginAuth
from tushu.except_my import CustomException
from tushu.filters_my import BooksFilter
from tushu.models import BookModel
from tushu.perssion_my import BlacklistPermission
from tushu.serializer import BookSerializer


class BookViewSet(ModelViewSet):
    queryset = BookModel.objects.all()
    serializer_class = BookSerializer

    # 自定义的 模糊查询--max_price min_price  btitle
    # filterset_class = BooksFilter
    search_fields = ['btitle']
    # 排序字段
    ordering_fields = ['id', 'price']

    def list(self, request):

        raise CustomException(data={'detail':"自己定义的报错！"},status_code=400)






    #  局部限流
    throttle_classes = [AnonRateThrottle]

